<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>颜色选择器</title>
</head>
<style>
  html,
  body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
  }

  main {
    width: 800px;
    height: 600px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
  }

  main div {
    margin-bottom: 20px;
  }
</style>

<body>
  <main>
    <div>
      <button id="open">打开</button>
      <button id="destroy">销毁</button>
    </div>
    <canvas height="313" width="500" id="canvas"></canvas>
  </main>
</body>
<script type="module">
  import ColorPicker from "./src/main.ts";
  let canvas = document.getElementById("canvas")
  let ctx = canvas.getContext("2d");
  let img = new Image();
  img.src = "https://songlh.top/page-color-picker/color_select.jpg"
  img.crossOrigin = "";
  ctx.drawImage(img, 0, 0, 500, 313)
  let picker = new ColorPicker({
    el: '#canvas',
    onChange: (color) => {
      console.log("获取颜色", color);
    }
  })
  document.getElementById("open").addEventListener("click", open)
  document.getElementById("destroy").addEventListener("click", destroy)
  function open() {
    picker.open()
  }
  function destroy() {
    picker.destroy();
  }
</script>

</html>